home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bitstrg.zip / CREBITAR.C < prev    next >
C/C++ Source or Header  |  1989-06-05  |  788b  |  36 lines

  1. /*
  2.     librairie : bitstrg
  3.  
  4.     crebitarray -- allocation memoire pour champ de bits
  5. */
  6.  
  7. #include <stdio.h>
  8. #include "bitstrg.h"
  9.  
  10. /*
  11.     Creation of an array of bit
  12.  
  13.     The array is initialized to all 0s
  14.     return a pointer on the array parameters structure or NULL if problem
  15. */
  16.  
  17. struct SPARRAY* crebitarray(nbbit)
  18.     unsigned nbbit;            /* number of the last bit in the array */
  19. {
  20.     unsigned value;            /* number of element in array */
  21.  
  22.     struct SPARRAY* pnt;
  23.  
  24.     value = (((long)nbbit+1) / SIZE )
  25.          + ((((long)nbbit+1) & (SIZE - 1)) ? 1 : 0);
  26.  
  27.     if((pnt = (struct SPARRAY *) calloc (1,sizeof(struct SPARRAY))) != NULL) {
  28.         if((pnt->pntarray = (ELEBAR*) calloc(value,sizeof(ELEBAR))) == NULL) {
  29.             free(pnt);
  30.             return(NULL);
  31.         }
  32.         pnt->numlbit = nbbit;
  33.     }
  34.     return(pnt);
  35. }
  36.